<?php
$this->pageTitle=Yii::app()->name . ' - Chọn bài viết';
$this->breadcrumbs=array(
	'Chọn bài viết',
);
?>
<style>
.clearBoth{clear:both;}
.ulListNone{list-style-type: none;}
.yiiPager{list-style-type: none;padding:0;margin:0;}
.yiiPager li{float:left;padding:3px 5px;}
.yiiPager li a{text-decoration: none;}
.item-control{padding:0;margin:0;}
.item-control li{float:left;}
.MLf15{margin-left:15px;}
.FLf{float:left;}
.FRt{float:right;}
.TACTr{text-align:center;}
.MRt10{margin-right:10px;}
.selected{background:#CCC;}
</style>
<br class="clearBoth"/>
<h1 class="TACTr">Tuyển chọn bài viết</h1>
<form method="GET" id="submit-type" action="http://localhost/bitool/index.php/test/select">
  <div class="MLf15">
    Từ khóa: <?php echo CHtml::textField('key-news',isset($_GET['key-news'])?$_GET['key-news']:'',array('style'=>'width:300px'))?>
    &nbsp;&nbsp;&nbsp;&nbsp;Nguồn: <?php echo CHtml::dropDownList('type',isset($_GET['type'])?$_GET['type']:0,$types,array('id'=>'post-type'))?>
    &nbsp;&nbsp;&nbsp;&nbsp;<?php echo CHtml::submitButton('Tìm kiếm');?>
  </div>
  <br />
</form>
<div class="vc-news borderC MLf15" style="width:900px;">
<br class="clearBoth"/>
<div class="comment-paging FRt MRt10">
        <?php $this->widget('CLinkPager', array(
                'pages' => $pages,
                'header'=>'',
                'cssFile'=>'false',
      //                  'nextPageLabel'=>'&nbsp;',
                'firstPageLabel'=>'<<',
                'lastPageLabel'=>'>>',
                'maxButtonCount'=>30
                )) ?>
</div><br class="clearBoth"/><br class="clearBoth"/>
<?php 
$i = 1;
foreach($news as $data):?>
	<div class="vc-news-item vc-news-detail-<?php echo $data->id;?>">
	   <ul class="item-control ulListNone P0 M0">
	     <li class="FLf MLf15"><b><?php echo $i;?></b></li>
	     <li class="FLf MLf15" style="width:550px;"><?php echo CHtml::link($data->title, $data->urlSource);?></li>
	     <li class="FLf MLf15">
	       <select class="category-item-<?php echo $data->id;?>">
	        <?php 
	          foreach($category as $key=>$c){
	            echo '<option value="'.$key.'">'.$c.'</option>';
	          }
	        ?>
	        </select>
	     </li>
	     <li class="FLf MLf15 btn-select-<?php echo $data->id;?>">
	       <?php if($data->selected_f):?>
	         <label style="background:green;color:#fff;">&nbsp;Đã chọn&nbsp;</label>
	       <?php else:?>
	         <input type="button" name="<?php echo $data->id;?>" class="select-item" value="Chọn" />
	       <?php endif;?>
	     </li>
	   </ul>
	   <div class="item-description clearBoth MLf15">
	     <img class="FLf MRt10" src="<?php echo $data->imageSRC;?>" width="100px"/>
	     <span class="">
	       <?php echo $data->summary;?>
	     </span>
	   </div>
	</div>
	<br class="clearBoth"/><br class="clearBoth"/>
	<hr class="hr-dot" />
<?php 
$i ++;
endforeach;?>
<div class="comment-paging FRt MRt10">
        <?php $this->widget('CLinkPager', array(
                'pages' => $pages,
                'header'=>'',
                'cssFile'=>'false',
      //                  'nextPageLabel'=>'&nbsp;',
                'firstPageLabel'=>'<<',
                'lastPageLabel'=>'>>',
                'maxButtonCount'=>30
                )) ?>
</div><br class="clearBoth"/>
</div>
<script>
$(document).ready( function(){
	//$('#post-type').change(function(){
	  //$('#submit-type').submit();
	//});
  $('.select-item').click(function(){
	  //alert($(this).attr("name"));
	  if($('.category-item-'+$(this).attr("name")).val()){
		  var aid = $(this).attr("name");
      $.ajax({
        type: 'POST',
        url: 'http://localhost/bitool/index.php/test/save',
        data: {id : $(this).attr("name"), cid : $('.category-item-'+$(this).attr("name")).val()},
        success: function(msg){
          if(msg == 1){
        	  $('.btn-select-'+aid).html('<label style="background:green;color:#fff;">&nbsp;Đã chọn&nbsp;</label>');
          } else {
        	  alert("Tuyển chọn thất bại, mời bạn thử lại!");
          }
        }
      });
	  } else {
		  alert('Bạn chưa chọn chuyên mục');
		}
	});
});
</script>